/**
 * autonavi.com Inc.
 * Copyright (c) 2004-${year} All Rights Reserved.
 */
package com.clm.interceptor;

import com.clm.common.ResultJson;
import com.google.gson.Gson;
import com.jfinal.aop.Interceptor;
import com.jfinal.core.ActionInvocation;

import javax.servlet.http.HttpSession;

/**
 * @author chong.song
 * @version 2014/6/25 23:06 chong.song
 */
public class LoginInterceptor implements Interceptor {
    @Override
    public void intercept(ActionInvocation ai) {
        HttpSession session = ai.getController().getSession();
        if(null != session && session.getAttribute("userName") != null){
            ai.invoke();
        }else{
            ResultJson json = new ResultJson();
            json.setCode(-1);
            json.setMessage("未登录，请先登录!");
            ai.getController().renderJson(new Gson().toJson(json));
        }
    }
}
